<template>
  <div class="container">
    <div class="search">
      <search/>
      <div class="today-commendation">
        <h4>Hi{{ user }} 今日为你推荐</h4>
      </div>
      <div class="scroll">
        <div class="items" v-for="item in list" :key="item.key">
          <img :src="item.url" alt="" />
        </div>
      </div>
    </div>
    <div
      class="list"
      v-for="item in musicList"
      :key="item.key"
      @click="play(item)"
    >
      <div class="list-item">
        <img :src="item.img_url" :alt="item.name" />
      </div>
      <div
        class="list-item"
        style="
          display: flex;
          flex-flow: column;
          justify-content: space-between;
          margin-top: 15px;
          margin-left: 10px;
        "
      >
        <div>
          <strong> {{ item.name }}</strong>
        </div>
        <div style="font-size: 15px">{{ item.singer }}</div>
      </div>
    </div>
      <drawer  ref="child"/>
  </div>
</template>
<script>
import service from "@/utils/service";
import drawer from "@/components/drawer";
import search from "@/components/search"

export default {
  name: "recommendation",
  components:{
        drawer,
        search
  },
  async mounted() {
    this.loadCallback();
  },
  data() {
    return {
      user: "",
      list: [
        {
          key: "1",
          url: require("../../radio/imgs/1.jpg"),
        },
        {
          key: "2",
          url: require("../../radio/imgs/1.jpg"),
        },
        {
          key: "3",
          url: require("../../radio/imgs/1.jpg"),
        },
        {
          key: "4",
          url: require("../../radio/imgs/1.jpg"),
        },
        {
          key: "5",
          url: require("../../radio/imgs/1.jpg"),
        },
      ],
      musicList: []
    };
  },
  methods: {
    async loadCallback() {
      let resp = await service.get("json/list.json");
      let array = resp || [];
      this.musicList = array;
    },
    play(item) {
      this.$store.dispatch('musicItem',item)
      this.$refs.child.musicPlay()
    }  
  }
};
</script>
<style scoped>
.search {
  margin: 5px 20px 20px 20px;
}
.scroll {
  min-width: 100%;
  max-width: 1000px;
  height: 100px;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  overflow-y: auto;
}
.items {
  width: 100px;
  height: 100px;
  border-radius: 20px;
  margin-right: 10px;
  flex: 1;
}
.items:first-child {
  flex-grow: 2;
}
.items:last-child {
  margin-right: 0px;
}
.items img {
  width: 100px;
  height: 100%;
  border-radius: 10px;
}
::-webkit-scrollbar {
  display: none;
}
.list {
  display: flex;
  margin: 0px 20px 0px 20px;
  border-bottom: 3px solid #f6f6f6;
}

.music-src {
  font-size: 21px;
  font-weight: 600;
  color: #ff7d15;
  width: 320px;
  margin: 20px auto 0;
}
.list-item img {
  width: 70px;
  height: 70px;
  border-radius: 5px;
}
</style>